﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using LibKetoan;
using System.Data;

namespace Ketoan
{
	/// <summary>
	/// Summary description for frmReport_kp1.
	/// </summary>
	public class frmReport_kp1 : System.Windows.Forms.Form
	{
		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmReport_kp1));
			this.grbThang = new System.Windows.Forms.GroupBox();
			this.numNam = new System.Windows.Forms.NumericUpDown();
			this.cboQuy = new System.Windows.Forms.ComboBox();
			this.cboChon = new System.Windows.Forms.ComboBox();
			this.label1 = new System.Windows.Forms.Label();
			this.lblThoiGian = new System.Windows.Forms.Label();
			this.cboThang = new System.Windows.Forms.ComboBox();
			this.label2 = new System.Windows.Forms.Label();
			this.butExcel = new System.Windows.Forms.Button();
			this.butKetthuc = new System.Windows.Forms.Button();
			this.butIn = new System.Windows.Forms.Button();
			this.butXem = new System.Windows.Forms.Button();
			this.grbThang.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.numNam)).BeginInit();
			this.SuspendLayout();
			// 
			// grbThang
			// 
			this.grbThang.Controls.AddRange(new System.Windows.Forms.Control[] {
																				   this.numNam,
																				   this.cboQuy,
																				   this.cboChon,
																				   this.label1,
																				   this.lblThoiGian,
																				   this.cboThang,
																				   this.label2});
			this.grbThang.Dock = System.Windows.Forms.DockStyle.Top;
			this.grbThang.Name = "grbThang";
			this.grbThang.Size = new System.Drawing.Size(442, 48);
			this.grbThang.TabIndex = 179;
			this.grbThang.TabStop = false;
			// 
			// numNam
			// 
			this.numNam.ForeColor = System.Drawing.Color.DarkBlue;
			this.numNam.Location = new System.Drawing.Point(384, 16);
			this.numNam.Maximum = new System.Decimal(new int[] {
																   2900,
																   0,
																   0,
																   0});
			this.numNam.Minimum = new System.Decimal(new int[] {
																   2004,
																   0,
																   0,
																   0});
			this.numNam.Name = "numNam";
			this.numNam.Size = new System.Drawing.Size(48, 20);
			this.numNam.TabIndex = 24;
			this.numNam.Value = new System.Decimal(new int[] {
																 2004,
																 0,
																 0,
																 0});
			// 
			// cboQuy
			// 
			this.cboQuy.ForeColor = System.Drawing.Color.DarkBlue;
			this.cboQuy.Items.AddRange(new object[] {
														"1",
														"2",
														"3",
														"4"});
			this.cboQuy.Location = new System.Drawing.Point(224, 16);
			this.cboQuy.Name = "cboQuy";
			this.cboQuy.Size = new System.Drawing.Size(64, 21);
			this.cboQuy.TabIndex = 23;
			// 
			// cboChon
			// 
			this.cboChon.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboChon.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.cboChon.ForeColor = System.Drawing.Color.DarkBlue;
			this.cboChon.ImeMode = System.Windows.Forms.ImeMode.NoControl;
			this.cboChon.Items.AddRange(new object[] {
														 " Tháng",
														 " Quý",
														 " Năm"});
			this.cboChon.Location = new System.Drawing.Point(96, 16);
			this.cboChon.Name = "cboChon";
			this.cboChon.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cboChon.Size = new System.Drawing.Size(72, 21);
			this.cboChon.TabIndex = 19;
			this.cboChon.SelectedIndexChanged += new System.EventHandler(this.cboChon_SelectedIndexChanged);
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.SystemColors.Control;
			this.label1.ForeColor = System.Drawing.Color.DarkBlue;
			this.label1.Location = new System.Drawing.Point(8, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(80, 23);
			this.label1.TabIndex = 18;
			this.label1.Text = "Báo cáo theo :";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// lblThoiGian
			// 
			this.lblThoiGian.BackColor = System.Drawing.SystemColors.Control;
			this.lblThoiGian.ForeColor = System.Drawing.Color.DarkBlue;
			this.lblThoiGian.Location = new System.Drawing.Point(176, 16);
			this.lblThoiGian.Name = "lblThoiGian";
			this.lblThoiGian.Size = new System.Drawing.Size(40, 23);
			this.lblThoiGian.TabIndex = 22;
			this.lblThoiGian.Text = "Tháng";
			this.lblThoiGian.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// cboThang
			// 
			this.cboThang.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboThang.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.cboThang.ForeColor = System.Drawing.Color.DarkBlue;
			this.cboThang.ImeMode = System.Windows.Forms.ImeMode.NoControl;
			this.cboThang.Items.AddRange(new object[] {
														  "01",
														  "02",
														  "03",
														  "04",
														  "05",
														  "06",
														  "07",
														  "08",
														  "09",
														  "10",
														  "11",
														  "12",
														  "6 tháng đầu năm",
														  "6 tháng cuối năm"});
			this.cboThang.Location = new System.Drawing.Point(224, 16);
			this.cboThang.Name = "cboThang";
			this.cboThang.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cboThang.Size = new System.Drawing.Size(104, 21);
			this.cboThang.TabIndex = 19;
			// 
			// label2
			// 
			this.label2.BackColor = System.Drawing.SystemColors.Control;
			this.label2.ForeColor = System.Drawing.Color.DarkBlue;
			this.label2.Location = new System.Drawing.Point(336, 16);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(40, 23);
			this.label2.TabIndex = 22;
			this.label2.Text = "Năm";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// butExcel
			// 
			this.butExcel.BackColor = System.Drawing.SystemColors.Control;
			this.butExcel.ForeColor = System.Drawing.SystemColors.WindowText;
			this.butExcel.Image = ((System.Drawing.Bitmap)(resources.GetObject("butExcel.Image")));
			this.butExcel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butExcel.Location = new System.Drawing.Point(156, 72);
			this.butExcel.Name = "butExcel";
			this.butExcel.Size = new System.Drawing.Size(60, 25);
			this.butExcel.TabIndex = 195;
			this.butExcel.Text = "&Excel";
			this.butExcel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butExcel.Click += new System.EventHandler(this.butExcel_Click);
			// 
			// butKetthuc
			// 
			this.butKetthuc.BackColor = System.Drawing.SystemColors.Control;
			this.butKetthuc.ForeColor = System.Drawing.SystemColors.WindowText;
			this.butKetthuc.Image = ((System.Drawing.Bitmap)(resources.GetObject("butKetthuc.Image")));
			this.butKetthuc.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butKetthuc.Location = new System.Drawing.Point(280, 72);
			this.butKetthuc.Name = "butKetthuc";
			this.butKetthuc.Size = new System.Drawing.Size(68, 25);
			this.butKetthuc.TabIndex = 197;
			this.butKetthuc.Text = "&Kết thúc";
			this.butKetthuc.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butKetthuc.Click += new System.EventHandler(this.butKetthuc_Click);
			// 
			// butIn
			// 
			this.butIn.BackColor = System.Drawing.SystemColors.Control;
			this.butIn.ForeColor = System.Drawing.SystemColors.WindowText;
			this.butIn.Image = ((System.Drawing.Bitmap)(resources.GetObject("butIn.Image")));
			this.butIn.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butIn.Location = new System.Drawing.Point(218, 72);
			this.butIn.Name = "butIn";
			this.butIn.Size = new System.Drawing.Size(60, 25);
			this.butIn.TabIndex = 196;
			this.butIn.Text = "     &In";
			this.butIn.Click += new System.EventHandler(this.butIn_Click);
			// 
			// butXem
			// 
			this.butXem.BackColor = System.Drawing.SystemColors.Control;
			this.butXem.ForeColor = System.Drawing.SystemColors.WindowText;
			this.butXem.Image = ((System.Drawing.Bitmap)(resources.GetObject("butXem.Image")));
			this.butXem.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butXem.Location = new System.Drawing.Point(94, 72);
			this.butXem.Name = "butXem";
			this.butXem.Size = new System.Drawing.Size(60, 25);
			this.butXem.TabIndex = 194;
			this.butXem.Text = "     &Xem";
			this.butXem.Click += new System.EventHandler(this.butXem_Click);
			// 
			// frmReport_kp1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(442, 128);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.butExcel,
																		  this.butKetthuc,
																		  this.butIn,
																		  this.butXem,
																		  this.grbThang});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "frmReport_kp1";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Load += new System.EventHandler(this.frmReport_kp1_Load);
			this.grbThang.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.numNam)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		#region Controls	
		private exportExcel exportExcel=new exportExcel();
		private System.Windows.Forms.GroupBox grbThang;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label lblThoiGian;
		private System.Windows.Forms.ComboBox cboThang;
		private System.Windows.Forms.ComboBox cboQuy;
		private System.Windows.Forms.NumericUpDown numNam;
		private System.Windows.Forms.Button butExcel;
		private System.Windows.Forms.Button butKetthuc;
		private System.Windows.Forms.Button butIn;
		private System.Windows.Forms.Button butXem;
		private System.Windows.Forms.ComboBox cboChon;
		private System.Windows.Forms.Label label2;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		#endregion

		#region Variable
		private AccessData a;
		private DataSet ds_Data;
		private int i_HTaikhoan=0,i_HLoaikhoan=0;
		private string s_Tenform="",s_Report="",ngayin="";
		string Madvqhns="",text="",ngaythangnam="",text1="";
		private int i_userid;
		#endregion	
				
		#region Constructor
		public frmReport_kp1(string s_Form,AccessData acc,int userid)
		{		
			InitializeComponent();
			a=acc;
			s_Tenform=s_Form;
			i_userid=userid;
		}
		#endregion

		#region Destructor
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#endregion

		#region Load Form
		private void frmReport_kp1_Load(object sender, System.EventArgs e)
		{
			cboChon.SelectedIndex =0;
			cboThang.SelectedValue=DateTime.Now.Month.ToString();
			cboQuy.SelectedIndex=0;
			ngayin = "Ngày " + DateTime.Now.Day.ToString() + " tháng ";
			ngayin += DateTime.Now.Month + " năm " + DateTime.Now.Year.ToString();
			numNam.Value=DateTime.Now.Year;
			f_Loadform();
		}
		#endregion

		#region Control Events
	
		#endregion

		#region Button Events
		private void butKetthuc_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void butIn_Click(object sender, System.EventArgs e)
		{
		
		}

		private void butXem_Click(object sender, System.EventArgs e)
		{
			Display(1);
		}

		private void butExcel_Click(object sender, System.EventArgs e)
		{
			Display(2);
		}
		#endregion

		#region Combobox Events
		private void cboChon_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			try
			{
				switch (cboChon.SelectedIndex)
				{
					case 0:
						lblThoiGian.Text = "Tháng";
						lblThoiGian.Enabled = true;
						cboThang.Visible=true;
						cboThang.Enabled=true;
						cboQuy.Visible=false;
						numNam.Visible=true;						
						cboThang.Text= DateTime.Now.Month.ToString().PadLeft(2,'0');						
						break;
					case 1:
						lblThoiGian.Text = "Quý";
						lblThoiGian.Enabled = true;
						cboThang.Visible=false;
						cboQuy.Enabled=true;
						cboQuy.Visible=true;
						numNam.Visible=true;
						int i_Quy=(int)((int.Parse(DateTime.Now.Month.ToString())-1)/3)+1;
						cboQuy.Text=Convert.ToString(i_Quy);						
						break;
					case 2:
						lblThoiGian.Text = "Tháng";
						lblThoiGian.Enabled=false;
						cboThang.Visible=true;
						cboThang.Enabled=false;
						cboQuy.Visible=false;
						numNam.Visible=true;	
						numNam.Value=DateTime.Now.Year;						
						break;
					default:
						cboThang.Visible=false;
						cboQuy.Visible=false;
						numNam.Visible=false;
						break;
				}
			}
			catch (Exception Ex)
			{
				MessageBox.Show("Error : " + Ex ,"Thông báo !");
			}
		}

		#endregion

		#region Functions
		private void f_Loadform()
		{

			i_HTaikhoan=2; i_HLoaikhoan=-2;
			switch (s_Tenform)
			{
				case "KPChuaSuDung":
					this.Text=" BÁO CÁO SỐ KINH PHÍ CHƯA SỬ DỤNG ĐÃ QUYẾT TOÁN NĂM TRƯỚC CHUYỂN SANG (MẤU SỐ B05-H)";
					i_HTaikhoan=2; i_HLoaikhoan=-4;
					s_Report="KT_BaoCaoKPChuaSuDung.rpt";
					break;	
				case "TangGiamTSCD":
					this.Text="BÁO CÁO TÌNH HÌNH TĂNG GIẢM TSCĐ (MẪU SỐ B04-H)";
					i_HTaikhoan=2; i_HLoaikhoan=-4;
					s_Report="KT_TangGiamTSCD.rpt";
					break;	
				case "ThuChiHoatDongSuNghiepSXKD":
					this.Text="BÁO CÁO THU CHI HOẠT ĐỘNG SỰ NGHIỆP VÀ SẢN XUẤT KINH DOANH ";
					i_HTaikhoan=2; i_HLoaikhoan=-4;
					s_Report="KT_BaoCaoThuChiHoatDongSuNghiep_SXKD.rpt";
					break;	
				case "Baocaotaichinh":
					this.Text="THUYẾT MINH BÁO CÁO TÀI CHÍNH (MẪU SỐ B06-H) ";
					i_HTaikhoan=2; i_HLoaikhoan=-4;
					s_Report="KT_Baocaotaichinh.rpt";
					break;
				case "BangCanDoiKeToan":
					this.Text="BẢNG CÂN ĐỐI KẾ TOÁN ";
					i_HTaikhoan=2; i_HLoaikhoan=-4;
					s_Report="KT_BangCanDoiKeToan.rpt";
					break;	
				case "KetQuaHoatDongKinhDoanh":
					this.Text="BÁO CÁO KẾT QUẢ HOẠT ĐỘNG KINH DOANH ";
					i_HTaikhoan=2; i_HLoaikhoan=-4;
					s_Report="KT_KetQuaHoatDongKinhDoanh.rpt";
					break;	
				case "LuuChuyenTienTe":
					this.Text="BÁO CÁO LƯU CHUYỂN TIỀN TỆ ";
					i_HTaikhoan=2; i_HLoaikhoan=-4;
					s_Report="KT_LuuChuyenTienTe.rpt";
					break;
				case "BaoCaoChiTietThu":
					this.Text = "BÁO CÁO CHI TIẾT THU ";
					butXem.Enabled = true;
					s_Report ="KT_BaoCaoChiTietThu1.rpt";
					break;
                case "BaoCaoChiTietChi":
                    this.Text = "BÁO CÁO CHI TIẾT CHI";
                    butXem.Enabled = true;
                    s_Report = "KT_BaoCaoChiTietChi.rpt";
                    break;	
				default:
					f_Loadform_Null();
					break;
			}
		}


		private void f_Loadform_Null()
		{
			try
			{
				this.Text="Báo cáo đang xây dựng!";					
				//				grpNen.Dispose(); 
				//				lblChuong.Dispose(); 
				//				lblLoaikhoan.Dispose(); 
				//				txtLoaikhoan.Dispose(); 
				//				txtTenloaikhoan.Dispose();
				//				lblHoatDong.Dispose();
				//				lblHoatDong.Dispose();
				//				butXem.Dispose(); butIn.Dispose(); 						
			}
			catch (Exception Ex)
			{
				MessageBox.Show("Error : " + Ex ,"Thông báo !");
			}		
			
		}


		private void Display(int loai)
		{
			string yy=Convert.ToString(numNam.Value.ToString());
			string mm1="",mm2="";
			//Tinh lai cac gia tri thang theo dieu kien chon ngay thang.
			if(cboChon.SelectedIndex==0)
			{
				switch (cboThang.SelectedIndex)
				{
					case 0 : mm1=mm2="01"; break;
					case 1 : mm1=mm2="02"; break;
					case 2 : mm1=mm2="03"; break;
					case 3 : mm1=mm2="04"; break;
					case 4 : mm1=mm2="05"; break;
					case 5 : mm1=mm2="06"; break;
					case 6 : mm1=mm2="07"; break;
					case 7 : mm1=mm2="08"; break;
					case 8 : mm1=mm2="09"; break;
					case 9 : mm1=mm2="10"; break;
					case 10: mm1=mm2="11"; break;
					case 11: mm1=mm2="12"; break;
					case 12: 
						mm1="01";
						mm2="06";
						break;
					case 13: 
						mm1="07";
						mm2="12";
						break;
					default: 
						break;
				}
			}
			else if(cboChon.SelectedIndex==1)
			{
				switch (cboQuy.SelectedIndex)
				{				
					case 0 : 
						mm1="01"; 
						mm2="03";
						break;
					case 1 : 
						mm1="04"; 
						mm2="06";
						break;
					case 2 : 
						mm1="07"; 
						mm2="09";
						break;
					case 3 : 
						mm1="10"; 
						mm2="12";
						break;
					default: 
						break;
				}
			}
			else
			{
				mm1="01";
				mm2="12";
			}

			string s_mm1=mm1.ToString().PadLeft(2,'0');
			string s_mm2=mm2.ToString().PadLeft(2,'0');
			string s_yyyy=yy.ToString().Trim();
			string s_yy=s_yyyy.Substring(2,2);

			string s_Thangnam=a.kt_Tinhsodu(s_mm2.ToString(),s_yy);
			if (s_Thangnam!="")
			{
				MessageBox.Show("Các tháng "+s_Thangnam.Substring(0,s_Thangnam.Length-1)+" chưa tính số dư!","Chú ý!");
				//xac minh co tinh so du
				if (MessageBox.Show ("Bạn có muốn kiểm tra số dư không ?",this.Text,MessageBoxButtons.YesNo, MessageBoxIcon.Question)== DialogResult.Yes)
				{
					//tinh so du
					string sql="",_tu="",_den="";
					_den=s_mm2+s_yyyy.Substring(2,2);			
					//lay thang tu						
					sql="select mmyy from (select *  from a_dtsd where substr(trim(mmyy),3,4)='"+s_yy+"' order by mmyy asc) where rownum=1";
					DataSet ds=new DataSet();
					ds=a.get_data(sql);
					if(ds!=null && ds.Tables[0].Rows.Count>0)
						_tu=ds.Tables[0].Rows[0]["mmyy"].ToString();
					else _tu=s_mm1+s_yyyy.Substring(2,2);			
					if (!a.bYyyy(s_yyyy))
					{
						MessageBox.Show("Số liệu năm "+s_yyyy+" chưa tạo !",a.Msg);
						return;
					}
					string s=a.KiemtraFb(_tu,_den);
					if (s!="")
					{
						MessageBox.Show("Số liệu tháng :"+s.Substring(0,s.Length-1)+" Năm "+s_yyyy+" bị khóa !");    		
						return;
					}
					else 
					{
						Cursor=Cursors.WaitCursor;                        
						a.KiemtraFb(_tu,_den,i_userid);
						Cursor=Cursors.Default;
					}
					//a.updSodu(_tu,a.Mmyy_sau(_den),i_Iduser,false);
					MessageBox.Show("Đã kiểm tra số dư cuối tháng "+_tu.Substring(0,2)+" đến tháng "+_den.Substring(0,2)+" năm 20"+s_yy+" !",a.Msg);					
					//
				}
				return;
			}

			if (cboChon.SelectedIndex ==2)text = "Năm " + numNam.Value.ToString();
			if (cboChon.SelectedIndex ==0)
			{
				if (cboThang.SelectedIndex ==12)text = "Tháng 01 đến tháng 06 Năm " + s_yyyy;
				else if (cboThang.SelectedIndex ==13) text = "Tháng 07 đến tháng 12 Năm " + s_yyyy;
				else text = "Tháng " + mm1 + " Năm " + s_yyyy;
			}
			if (cboChon.SelectedIndex ==1)text = "Quý " + cboQuy.Text + " Năm " + s_yyyy;
            			
			ds_Data=new DataSet();

			//xoa du lieu cu cua ban a_sdr truoc khi dien du lieu moi
			string sql1 = "truncate table " + a.user + ".a_sdr";
			a.execute_data(sql1);
			//xoa du lieu cu cua ban a_sdr truoc khi dien du lieu moi
			string sql2 = "truncate table " + a.user + ".a_sdrct";
			a.execute_data(sql2);

			frmReport_kp1_class accMyform=new frmReport_kp1_class();
			if(s_Tenform!="BaoCaoChiTietThu")
			{			
				//accMyform.a_sdr_fs(a,mm1,mm2,s_yy,i_userid);
				accMyform.a_sdr_sd(a,mm1,mm2,s_yy,i_userid);
				//accMyform.a_sdrct_fs(a,mm1,mm2,s_yy,i_userid);
				//accMyform.a_sdrct_sd(a,mm1,mm2,s_yy,i_userid);
				accMyform.a_fbr(a,mm1,mm2,s_yy,i_userid);				
				a.get_data("update "+a.user+".a_congthuc set stien=0");
				accMyform.a_congthuc(a);
			}
			string idm="";	
			long l_idm=0;
			switch (s_Tenform)
			{	
				case "KPChuaSuDung":
					idm="";
					l_idm=long.Parse(a.getrowbyid(a.get_data("select * from "+a.user+".a_dmmaubc where maubieu='"+idm+"'").Tables[0],"maubieu='"+idm+"'")["id"].ToString().Trim());	
					ds_Data = accMyform.getData(a,1);
					break;
				case "TangGiamTSCD":
					idm="B04-H";
					l_idm=long.Parse(a.getrowbyid(a.get_data("select * from "+a.user+".a_dmmaubc where maubieu='"+idm+"'").Tables[0],"maubieu='"+idm+"'")["id"].ToString().Trim());
					ds_Data = accMyform.getData(a,3);
					break;
				case "ThuChiHoatDongSuNghiepSXKD":
					idm="B05-H";
					l_idm=long.Parse(a.getrowbyid(a.get_data("select * from "+a.user+".a_dmmaubc where maubieu='"+idm+"'").Tables[0],"maubieu='"+idm+"'")["id"].ToString().Trim());
					//ds_Data = accMyform.getData(a,2);
					ds_Data=accMyform.getData_1(a,l_idm,s_Tenform,s_yy);
					break;	
				case "BangCanDoiKeToan":
					idm="";
					//l_idm=long.Parse(a.getrowbyid(a.get_data("select * from "+a.user+".a_dmmaubc where maubieu='"+idm+"'").Tables[0],"maubieu='"+idm+"'")["id"].ToString().Trim());
					ds_Data = accMyform.getData_(a,6);
					break;	
				case "Baocaotaichinh":
					idm="B09_DN";
					l_idm=long.Parse(a.getrowbyid(a.get_data("select * from "+a.user+".a_dmmaubc where maubieu='"+idm+"'").Tables[0],"maubieu='"+idm+"'")["id"].ToString().Trim());
					//ds_Data = accMyform.getData_(a,6);
					ds_Data=accMyform.getData_1(a,l_idm,s_Tenform,s_yy);
					break;	
				case "LuuChuyenTienTe":
					idm="B03_DN";
					l_idm=long.Parse(a.getrowbyid(a.get_data("select * from "+a.user+".a_dmmaubc where maubieu='"+idm+"'").Tables[0],"maubieu='"+idm+"'")["id"].ToString().Trim());
					ds_Data = accMyform.getData_(a,5);
					break;	
				case "KetQuaHoatDongKinhDoanh":
					idm="";
					l_idm=long.Parse(a.getrowbyid(a.get_data("select * from "+a.user+".a_dmmaubc where maubieu='"+idm+"'").Tables[0],"maubieu='"+idm+"'")["id"].ToString().Trim());
					ds_Data = accMyform.getData_(a,4);
					break;
				case "BaoCaoChiTietThu":
					idm="B05-H";
					l_idm=long.Parse(a.getrowbyid(a.get_data("select * from "+a.user+".a_dmmaubc where maubieu='"+idm+"'").Tables[0],"maubieu='"+idm+"'")["id"].ToString().Trim());
					ds_Data = accMyform.getDatanew(a,s_mm1, s_mm2, s_yy );
					break;
				default: 
					break;
			}
		
			try
			{
				if (ds_Data==null) MessageBox.Show("Không có số liệu !","Thông báo !");
				else
				{	
					switch(loai)
					{
						case 1:
							if(s_Tenform=="BaoCaoChiTietThu")
							{
								frmReport f=new frmReport(a,ds_Data,s_Report,ngayin,Madvqhns,text,text1);
								f.ShowDialog();
								frmReport fa=new frmReport(a,ds_Data,"KT_BaoCaoChiTietThu2.rpt",ngayin,Madvqhns,text,text1);
								fa.ShowDialog();
							}
							else
							{
								frmReport f=new frmReport(a,ds_Data,s_Report,ngayin,Madvqhns,text,text1);
								f.ShowDialog();
							}
							break;
						case 2:
							string s_ExcelError=exportExcel.expExcel(a,ds_Data,"",ngaythangnam,"","","","","","","","","","","",s_Report.ToString());
							if (s_ExcelError!="")
								MessageBox.Show(s_ExcelError,"Thông báo!");
							break;
						default:
							break;
					}
				}
			}
			catch (Exception Ex)
			{
				MessageBox.Show("Error : " + Ex ,"Thông báo !");
			}
		}

		#endregion                 


	}
}
